package com.zlx.xbhy.mapper;

import com.zlx.xbhy.entity.Article;
import com.zlx.xbhy.entity.User;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

/**
 * @Author 周罗校
 * @Description
 * @ClassName ArticleMapper
 * @date 2020.11.18 15:12:21
 * 该版权归周罗校所有，最终解释权以官方为准
 */
public interface ArticleMapper extends Mapper<Article> {
    @Select("SELECT * FROM article WHERE title LIKE CONCAT('%',#{title},'%')")
    List<Article> selectPage(String title);
    
    /*
     * @Author Edward
     * @Description 查找当前用户收藏的全部文章  
     * @Date 19:26 2020/11/19
     * @Param uId
     * @return List<Article>
     **/
    @Select("SELECT " +
            "a.*  " +
            "FROM " +
            "article a  " +
            "WHERE " +
            "id IN ( SELECT f.a_id FROM favorite f WHERE f.u_id = #{uId}) " +
            "AND a.title LIKE CONCAT('%',#{title},'%')")
    public List<Article> selectFavoritePage(@Param("uId") Long uId,@Param("title") String title);

    @Select("SELECT " +
            "COUNT( 1 ) count, " +
            "DATE_FORMAT( DATE_SUB( NOW(), INTERVAL ${day} DAY ), '%m-%d' ) nowDate  " +
            "FROM " +
            "article  " +
            "WHERE " +
            "to_days( " +
            "now()) - to_days( publish_date )= #{day}")
    Article countNew(Integer day);
}

